<script setup lang="ts">
import { useChannelStore } from "@/stores/channel";
import type { AxiosResponse, channel, channelResponse } from "@/types";
import axios from "axios";
import { onMounted, ref } from "vue";

// defineProps<{ channelId: number }>();

// defineEmits<{ "update:channelId": [channelId: number] }>();

const store = useChannelStore();

const channels = ref<channel[]>([]);

const getData = async () => {
  const res = await axios.get<AxiosResponse<channelResponse>>(
    "http://geek.itheima.net/v1_0/channels"
  );
  channels.value = res.data.data.channels;
};

onMounted(() => {
  getData();
});
</script>

<template>
  <div class="channel-nav">
    <nav class="list">
      <a
        class="item"
        :class="{ active: store.channelId === item.id }"
        href="javascript:;"
        v-for="(item, i) in channels"
        :key="item.id"
        @click="store.updateChannelId(item.id)"
      >
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>
